<template>
	<view class="content">
		<view class="indicator" @click="prevImage(index)" v-for="item,index in img" :key="index">
			<image :src="item" mode="widthFix"></image>
		</view>
		<view class="pro-details">
			<view class="pro-detai-box">
				<view class="pro-id">商品编号：{{ info.goods_no }}</view>
				<view class="price-proid">
					<view class="price">
						<text class="price-icon">￥</text>
						<u-count-to :startVal="0" :endVal="info.sell_price" :decimals="2" fontSize="38rpx" color="#f18b49" style="margin-right: 15rpx;"></u-count-to>
					</view>
					<view style="color: #f18b49;margin-top: 30rpx; font-size: 28rpx;" @click="copy()">复制标题</view>
				</view>
				<view class="pro-tit" @click="copy()">{{ info.name}}</view>
				<view style="color: #999;margin-top: 30rpx; font-size: 28rpx;">
					<text>商品店铺：</text>{{ infoName }}
				</view>
				<view style="color: #f18b49;margin-top: 30rpx; font-size: 28rpx;" @click="toUrl()" v-show="info.selfPlatformLink != '' && info.selfPlatformLink != 'http://www.xxx.com'">
					<text style="color: #999;" >商品链接：</text>{{ info.selfPlatformLink }}
					<!-- <text style="color: #999; padding-left: 20rpx;">跳转链接</text> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				img: [],
				info: {},
				infoName: '',
				currentNum: '',
				baseUrl: 'http://www.hy-dzsc.com/'
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getDetail()
		},
		computed:{
			myName(){
				if(Object.keys(this.info).length != 0){
					const index = this.info.name.lastIndexOf("】")
					return this.info.name.substr(index + 1)
				}
			},
		},
		methods: {
			// 获取商品详情
			getDetail() {
				uni.request({
					url: `${this.baseUrl}gjcApi/products?goods_id=${this.id}`,
					data: {},
					header: { 'content-type': 'application/x-www-form-urlencoded' },
					method:'GET',
					success: res => {
						this.info = res.data
						this.infoName = res.data.seller.true_name
						this.img.push(this.baseUrl + res.data.img)
					}
				})
			},
			// 预览图片
			prevImage(i) {
				uni.previewImage({
					current: i,
					urls: this.img,
				})
			},
			// 链接跳转
			toUrl(){
				uni.navigateTo({
					url: '/pages/index/webview?url=' + this.info.selfPlatformLink
				})
			},
			// 复制
			copy(){
				uni.setClipboardData({
					data: this.myName,
					success: (res) => {
						uni.showToast({
							title: '已复制',
							duration: 1000,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.indicator {
			image{
				width: 750rpx;
			}
		}
		.pro-details {
			padding: 20rpx 15rpx 0 15rpx;

			.pro-detai-box {
				border-radius: 20rpx;
				background: $uni-model-color;
				padding: 25rpx 25rpx 30rpx 25rpx;

				.pro-id {
					display: flex;
					font-size: 26rpx;
					flex-direction: row-reverse;
					color: $uni-text-color-disable;
				}

				.price-proid {
					display: flex;
					font-size: 26rpx;
					align-items: baseline;
					margin: 10rpx 0 15rpx 0;
					justify-content: space-between;

					.price {
						.price-icon {
							color: $uni-text-color;
						}
					}

					.pro-detai-bot {
						display: flex;
						font-size: 24rpx;
						align-items: center;
						flex-direction: row-reverse;
						color: $uni-text-color-grey;
					}
				}

				.pro-tit {
					user-select: text;
					font-size: 30rpx;
					font-weight: bold;
					letter-spacing: 1rpx;
				}

				.pro-select {                                    
					display: flex;
					font-size: 24rpx;
					margin: 30rpx 0 20rpx 0;
					color: $uni-text-color-grey;

					text {
						flex-shrink: 0;
					}

					.sel-class-box {
						display: flex;
						flex-wrap: wrap;

						.sel-class {
							display: flex;
							// padding: 14rpx 35rpx;
							margin: 0 20rpx 15rpx 0;

							// background: $uni-border-color;
							.message-class {
								padding: 14rpx 35rpx;
								margin: 0 20rpx;
								background: #f3f3f3;
							}

							.sel-class-active {
								padding: 12rpx 35rpx;
								color: $uni-text-color;
								margin: 0 20rpx 15rpx 0;
								border: 2rpx solid $uni-text-color;
							}
						}
					}
				}

				.pro-number {
					display: flex;
					font-size: 30rpx;
					align-items: center;
					color: $uni-text-color-grey;
					justify-content: space-between;
				}
			}
		}

		.cont-img {
			padding-bottom: 95rpx;

			image {
				width: 100%;
			}
		}

		.bot-nav {
			display: flex;
			width: 750rpx;
			position: fixed;
			padding: 10rpx 0rpx;
			align-items: center;
			background: $uni-model-color;
			bottom: var(--window-bottom, 0);
			justify-content: space-between;
			border-top: 2rpx solid $uni-border-color;

			.nav-left {
				display: flex;
				text-align: center;
				padding-left: 30rpx;
				color: $uni-text-color-grey;

				.left-box-1 {
					.left-txt-1 {
						font-size: 22rpx;
					}
				}

				.left-box-2 {
					margin-right: 35rpx;

					.left-txt-2 {
						font-size: 22rpx;
					}
				}
			}

			.nav-right {
				display: flex;
				font-size: 26rpx;
				margin-right: 20rpx;
				align-items: center;
				color: $uni-model-color;

				.nav-right-leftbtn {
					background: red;
					padding: 24rpx 70rpx;
					border-radius: 50rpx 0 0 50rpx;
				}

				.nav-right-rightbtn {
					background: #ffa200;
					padding: 24rpx 83rpx;
					border-radius: 0 50rpx 50rpx 0;
				}
			}
		}
	}
</style>